//
//  ApplyOilFirstVC.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/11.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "ApplyOilFirstVC.h"
#import "ApplyOilSecondVC.h"
#import "ApplyeOilHeadView.h"

#import "OilCardPersonnalView.h"
#import "OilCardCompanyView.h"

@interface ApplyOilFirstVC ()

@property (nonatomic, strong) ApplyeOilHeadView *stepHeadView;
@property (nonatomic, strong) UIScrollView *contenView;

///!
@property (nonatomic, strong) OilCardPersonnalView *personnalView;
@property (nonatomic, strong) OilCardCompanyView *companyView;

@end

@implementation ApplyOilFirstVC

- (OilCardPersonnalView *)personnalView {
  if (!_personnalView) {
    _personnalView = [[OilCardPersonnalView alloc] initWithFrame:CGRectMake(0, _stepHeadView.yt_bottom, ScreenWidth, 0)];
  }
  return _personnalView;
}

- (OilCardCompanyView *)companyView {
  if (!_companyView) {
    _companyView = [[OilCardCompanyView alloc] initWithFrame:CGRectMake(0, _stepHeadView.yt_bottom, ScreenWidth, 0)];
  }
  return _companyView;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
//  [self setDefaltNavBar];
  [self.navigationController setNavigationBarHidden:NO animated:animated];
  [self setNavImage:[UIImage imageNamed:@"Home_BgImage"] titleColor:[UIColor whiteColor]];
  [self setStatusBarStyleWhite];

}


- (void)createFields {
  [super createFields];
  self.navigationItem.title = YTLocalizedString(@"油咭申请");
  [self createWhiteBack];
  _applyModel = [[OilApplyTotalModel alloc] init];
  _applyModel.isPersonal = YES;
  
}

- (void)createViews {
  [super createViews];
  
  _contenView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - NavBarHeight - 50)];
  [self.view addSubview:_contenView];
  
  _stepHeadView = [[ApplyeOilHeadView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenWidth * ITEMPRO)];
  [_contenView addSubview:_stepHeadView];
  __weak typeof(self) weakSelf = self;
  _stepHeadView.checkPersonal = ^{
    weakSelf.applyModel.isPersonal = weakSelf.stepHeadView.isPersonal;
    [weakSelf changeContenView];
  };
  
  [self createApplyView];
  
  
}


- (void)createApplyView {
  
  [self changeContenView];
  
  ///! 取消
  UIButton *cancelButton = [[UIButton alloc] initWithFrame:CGRectMake(0, _contenView.yt_bottom + 10, 30 * 5, 30)];
  [cancelButton setTitle:YTLocalizedString(@"取消") forState:UIControlStateNormal];
  cancelButton.backgroundColor = DEF_GRAY;
  cancelButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  [cancelButton addTarget:self action:@selector(cancelclick) forControlEvents:UIControlEventTouchUpInside];
  cancelButton.yt_right = _contenView.yt_centerX - 5;
  cancelButton.layer.masksToBounds = YES;
  cancelButton.layer.cornerRadius = 8;
  [self.view addSubview:cancelButton];
  
  ///! 下一步
  UIButton *nextStepButton = [[UIButton alloc] initWithFrame:CGRectMake(cancelButton.yt_right + 10, cancelButton.yt_top, cancelButton.yt_width, cancelButton.yt_height)];
  [nextStepButton setTitle:YTLocalizedString(@"下一步") forState:UIControlStateNormal];
  nextStepButton.backgroundColor = DEF_RED;
  nextStepButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  [nextStepButton addTarget:self action:@selector(nextclick) forControlEvents:UIControlEventTouchUpInside];
  nextStepButton.layer.masksToBounds = YES;
  nextStepButton.layer.cornerRadius = 8;
  [self.view addSubview:nextStepButton];
  
}

- (void)changeContenView {
  
  if (_applyModel.isPersonal) {
    ///! 个人
    [_companyView removeFromSuperview];
    [_contenView addSubview:self.personnalView];
    _contenView.contentSize = CGSizeMake(ScreenWidth,  self.personnalView.yt_bottom + 10);

  } else {
    [_personnalView removeFromSuperview];
    [_contenView addSubview:self.companyView];
    _contenView.contentSize = CGSizeMake(ScreenWidth,  self.companyView.yt_bottom + 10);
  }
  
}

- (void)cancelclick {
  
}

- (void)nextclick {
  
  ApplyOilSecondVC *secondVC = [[ApplyOilSecondVC alloc] init];
  secondVC.applyModel = self.applyModel;
  [self.navigationController pushViewController:secondVC animated:YES];
  
}

@end

